<template>
    <div class="register">
        <login-top navto_url='/login' navto_title="用户登陆" title='注册bilibili'></login-top>
        <login-input @valueChange='input' label="姓名" style="margin:1rem 0" placeholder="请输入姓名" name="name"></login-input>
        <login-input @valueChange='input' label="账号" placeholder="请输入账号" name="id"></login-input>
        <login-input @valueChange='input' label="密码" type="password" placeholder="请输入密码" name="psw"></login-input>
        <login-button text='注册' style="margin-top:1.5rem" @submit="registerSubmit" ></login-button>
    </div>
</template>

<script>
import LoginTop from '../components/common/LoginTop.vue'
import LoginInput from '../components/common/LoginInput.vue'
import LoginButton from '../components/common/LoginButton.vue'
export default {
    data(){
        return{
            name:'name',
            id:'',
            psw:''
        }
    },
    components:{
        LoginTop,
        LoginInput,
        LoginButton
    },
    methods:{
        registerSubmit(){
            this.$http.post('/register',{
                name:this.name,
                username:this.id,
                password:this.psw
            }).then(res=>{
                if(res.data.id){
                    this.$toast.success(res.data.msg)   
                }
                else{
                    this.$toast.fail(res.data.msg)
                }
                console.log(this)
                console.log(res)
            })
            
        },
        input(value){
            this[event.target.name]=value
        }
    }

}
</script>